<?php
namespace app\admin\controller;

use app\admin\logic\CarLogic;
use app\admin\logic\CheckLogic;
use app\admin\logic\UserLogic;
use think\Request;

class Car extends Base{
	private $carLogic;
	public function __construct( Request $request = null ) {
		parent::__construct( $request );
		$this->carLogic=new CarLogic();
	}

	// 列表页
	public function index(){
		$cars=$this->carLogic->query('');
		$this->assign('list',$cars);
		return $this->fetch();
	}

	//新增用户页面
	public function add($car_num=''){
		$car=null;
		if(!empty($car_num)){
			$car=$this->carLogic->findOne($car_num);
		}
		$this->assign('car',$car);
		return $this->fetch();
	}

	// 根据车牌获取车辆信息
	public function findByNum($car_num){
		return $this->carLogic->findOne($car_num);
	}

	//保存数据
	public function doAdd($param=''){
		$carArr=json_decode($param,true);

		if (isset($carArr["car_type_a"])){
			$carArr["car_type"] = $carArr["car_type_a"] . '-' . $carArr["car_type_b"] . '-' . $carArr["car_type_c"];
		}

		$res=$this->carLogic->add($carArr);
		return $res;
	}

	//删除数据
	public function del($car_num=''){
		$res=$this->carLogic->del($car_num);
		return $res;
	}


	public function indexFleet(){
		return $this->fetch();
	}

	// 维修技师打开车辆服务页面
	public function addCar(){

		return $this->fetch();
	}

	// 维修技师打开车辆服务页面 (单一表单数据)
	public function addCarSingleForm(){
		//维修技师人员
		$userLogic=new UserLogic();
		$repairmen=$userLogic->query(['roles'=>8]);
		$this->assign('repairmen',$repairmen);
		//检查项目数据
		$checkLogic=new CheckLogic();
		$checks=$checkLogic->findDefaultCheck();
		$this->assign('check',$checks);
		return $this->fetch();
	}
	//获取车辆数据
	public function getCar($page=1,$rows=10,$q=''){
		$data=$this->carLogic->queryJqGrid('',$page,$rows,$q);
		return $data;
	}

	/**
	 * 打开充值记录首页
	 * @return mixed
	 */
	public function indexMoneyLog(){
		return $this->fetch();
	}


	/**
	 * 获取充值记录数据
	 * @param int $page
	 * @param int $rows
	 * @param string $q
	 *
	 * @return mixed
	 */
	public function getMoneyLog($page=1,$rows=10,$q='',$sidx='',$sord=''){
		return $this->carLogic->getMoneyLog($page,$rows,$q,$sidx,$sord);
	}
}


